<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use Illuminate\Support\Facades\DB;

Route::get('/', function () {
    return view('welcome');
});

// 用于显式上传表单
Route::get('form/page', 'RequestController@formPage');
Route::post('form', 'RequestController@form')->name('form.submit');
// 用于处理文件上传
Route::post('form/file_upload', 'RequestController@fileUpload');

//从数据库获取指定查询结果后，以主键 ID 值为键，以某个字段值为值构建关联数组
Route::get('db/pluck', function () {
    return DB::table('users')->pluck('name', 'id');
});
//其分割成多个的组块依次返回进行处理
Route::get('db/chunk', function() {
    $user = [];
    DB::table('users')->orderBy('id')->chunk(5, function ($users) use(&$user) {
        foreach ($users as $v) {
            $user[] = $v;
        }
    });
    return $user;
});